<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2272：[Usaco2011 Feb]Cowlphabet  奶牛文字</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Usaco2011 Feb]Cowlphabet  奶牛文字</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Usaco2011 Feb]Cowlphabet  奶牛文字</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                [Usaco2011 Feb]Cowlphabet  奶牛文字                </h1>
                <p>时间限制：10s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><p><span style="font-size: medium"><br />
Like all bovines, Farmer John's cows speak the peculiar 'Cow'<br />
language. Like so many languages, each word in this language comprises<br />
a sequence of upper and lowercase letters (A-Z and a-z).&nbsp; A word<br />
is valid if and only if each ordered pair of adjacent letters in<br />
the word is a valid pair.<br />
<br />
Farmer John, ever worried that his cows are plotting against him,<br />
recently tried to eavesdrop on their conversation. He overheard one<br />
word before the cows noticed his presence. The Cow language is<br />
spoken so quickly, and its sounds are so strange, that all that<br />
Farmer John was able to perceive was the total number of uppercase<br />
letters, U (1 &lt;= U &lt;= 250) and the total number of lowercase<br />
letters, L (1 &lt;= L &lt;= 250) in the word.<br />
<br />
Farmer John knows all P (1 &lt;= P &lt;= 200) valid ordered pairs of<br />
adjacent letters.&nbsp; He wishes to know how many different valid<br />
words are consistent with his limited data.&nbsp; However, since<br />
this number may be very large, he only needs the value modulo<br />
97654321.<br />
<br />
</span></p>
<div><span style="font-size: medium">&nbsp;&nbsp;&nbsp;约翰的奶牛讲的是别人听不懂的&ldquo;牛语&rdquo;。牛语使用的字母就是英文字母，有大小写之分。牛语中存在P个合法的词素，每个词素都由两个字母组成。牛语的单词是由字母组成的序列，一个单词是有意义的充要条件是任意相邻的字母都是合法的词素。</span></div>
<div><span style="font-size: medium">&nbsp;&nbsp;&nbsp;&nbsp;约翰担心他的奶牛正在密谋反对他，于是最近一直在偷听他们的对话。可是，牛语太复</span></div>
<div><span style="font-size: medium">杂了，他模模糊糊地只听到了一个单词，并确定了这个单词中有U个大写字母，L个小写字</span></div>
<div><span style="font-size: medium">母。现在他想知道，如果这个单词是有意义的，那么有多少种可能性呢？由于这个数字太大</span></div>
<div><span style="font-size: medium">了，你只要输出答案取97654321的余数就可以了。</span></div></p><hr/><h3>输入格式</h3><p><p><span style="font-size: medium"><br />
* Line 1: Three space-separated integers: U, L and P<br />
<br />
* Lines 2..P+1: Two letters (each of which may be uppercase or<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lowercase), representing one valid ordered pair of adjacent<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; letters in Cow.<br />
<br />
</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: medium"><span lang="EN-US"><font face="Times New Roman">&nbsp;&nbsp;</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一行：三个用空格隔开的整数：</span><span lang="EN-US"><font face="Times New Roman">U</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span><span lang="EN-US"><font face="Times New Roman">L</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US"><font face="Times New Roman">P</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span><span lang="EN-US"><font face="Times New Roman">1</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">&le;</span><span lang="EN-US"><font face="Times New Roman">U</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">．</span><span lang="EN-US"><font face="Times New Roman">L</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">&le;</span><span lang="EN-US"><font face="Times New Roman">250</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span><span lang="EN-US"><font face="Times New Roman">1</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">&le;</span><span lang="EN-US"><font face="Times New Roman">P&lt;=</font></span><span lang="EN-US"><font face="Times New Roman">200</font></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: medium"><span lang="EN-US"><font face="Times New Roman">&nbsp;&nbsp;</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第二行到</span><span lang="EN-US"><font face="Times New Roman">P+1</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行：第</span><span lang="EN-US"><font face="Times New Roman">i+l</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有两个字母，表示第</span><span lang="EN-US"><font face="Times New Roman">i</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个词素，没有两个词素是完全相同的</span></span></p>
<p></p></p><hr/><h3>输出格式</h3><p><p><span style="font-size: medium"><br />
* Line 1: A single integer, the number of valid words consistent with<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Farmer&nbsp; John's data mod 97654321.<br />
<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">单个整数，表示符合条件的单词数量除以</span><span lang="EN-US" style="font-family: &quot;Times New Roman&quot;; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">97654321</span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">的余数</span></span></p></p><hr/><h3>样例输入</h3><pre>2 2 7
AB
ab
BA
ba
Aa
Bb
bB

INPUT DETAILS:

The word Farmer John overheard had 2 uppercase and 2 lowercase
letters.  The valid pairs of adjacent letters are AB, ab, BA, ba,
Aa, Bb and bB.

</pre><hr/><h3>样例输出</h3><pre>7

</pre><hr/><h3>提示</h3><p><p><span style="font-size: medium"><span lang="EN-US" style="font-family: &quot;Times New Roman&quot;; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">(</span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">可能的单词为</span><span lang="EN-US" style="font-family: &quot;Times New Roman&quot;; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">AabB,&nbsp;Abba,&nbsp;abBA,&nbsp;BAab,BbBb,&nbsp;bBAa,&nbsp;bBbB)</span></span></p></p><hr/><h3>题目来源</h3><p>Gold</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2272" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2272" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>